home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
SAT 2.3.8
/
Demos
/
StepPlatform Demo ƒ
/
sPlayerSprite.c
< prev
next >
Wrap
Text File
|
1996-05-11
|
4KB
|
147 lines
/* Player sprite for the Platform test */
#include "SAT.h"
#include "myPlatform.h"
#ifndef abs
#define abs(x) (x>0?x:-x)
#endif
#define PlayerHigh 64
#define PlayerSpeed 5
#define Gforce 2 //like g = 9.8 m/sec^2
#define JumpSpeed 23
FacePtr rightFaces[4], leftFaces[4];
FacePtr fallFace[2] ;
void HandleKeys(PlSpritePtr me);
void InitPlayerSprite()
{
int i;
for(i=0;i<=3;i++){
leftFaces[i] = SATGetFace(128 + i);
rightFaces[i] = SATGetFace(132 + i);
}
for(i=0;i<=1;i++)
fallFace[i] = SATGetFace(136 + i);
}
pascal void HandlePlayerSprite(PlSpritePtr me)
{
EventRecord theEvent;
char temp;
HandleKeys(me);
/* Vspeed Limit ,Acceleration and Updating V Position */
if (me->speed.v > 30) me->speed.v = 30;
me->speed.v += Gforce;
me->position.v += me->speed.v;
/* Keeping the Hero with the same speed as the HMov platform */
if (me->action == JumpFromHMov)
me->position.h += me->speed.h;
/*Make sure we are always visible!*/
/*************************/
if (me->position.v < 0){
me->position.v = 0;
me->speed.v = 0;
}
if(me->position.h < 0){
me->position.h = 0;
me->speed.h = 0;
}
if(me->position.v > gSAT.offSizeV - PlayerHigh) {
me->action = Stand;
me->position.v = gSAT.offSizeV - PlayerHigh;
me->speed.v=0;
}
if(me->position.h > gSAT.offSizeH - PlayerHigh){
me->position.h = gSAT.offSizeH - PlayerHigh;
me->speed.h = 0;
}
me->mode = abs(me->mode + 1);
me->layer = -1*(me->position.v);
}
pascal void SetupPlayerSprite(PlSpritePtr me)
{
me->action = Stand;
me->mode = 0;
me->speed.h = 0;
me->kind = 1; /* friend kind */
SetRect(&(me->hotRect), 12, 0, PlayerHigh-10, PlayerHigh);
me->face = fallFace[0];
me->task = (void *)&HandlePlayerSprite;
me->hitTask = &HitPlayerSprite;
}
pascal void HitPlayerSprite(SpritePtr me, SpritePtr him)
{
/* Hit something! We can take whatever action we need here, but in this case,
we let the other sprites decide. We could have omitted this function altogether and passed nil.*/
if(him->kind == 1){
}
else if(him->kind == 2 )
{
}
}
void HandleKeys(PlSpritePtr me)
{
// RIGHT - Key Number 6
if (IsPressed(0x7B) || IsPressed(0x56)) /* left */
{
if (me->action==JumpFromHMov)
me->position.h -= PlayerSpeed-abs(me->speed.h);
else
me->position.h -= PlayerSpeed;
me->speed.h = -PlayerSpeed;
me->face = leftFaces[(me->mode/3) & 3];
}
// LEFT - Key Number 4
if (IsPressed(0x7C) || IsPressed(0x58)) /* right */
{
if (me->action==JumpFromHMov) //stay on the platform
me->position.h += PlayerSpeed-abs(me->speed.h);
else
me->position.h += PlayerSpeed;
me->speed.h = PlayerSpeed;
me->face = rightFaces[(me->mode/3) & 3]; //replace the face
}
// Not JUMP - not pushing key num 8 ,to prevent auto jumping!
if (! (IsPressed(0x7E) || IsPressed(0x5B)))
me->JumpKey = NotPushed;
// JUMP - Key Number 8
if (IsPressed(0x7E) || IsPressed(0x5B))
{
if (me->speed.v < 10) {
if ((me->JumpKey==NotPushed) &&((me->action!=Jump)&&(me->action!=JumpFromHMov))) {
me->speed.v = -JumpSpeed;
if (me->action == StandOnHMovPlatform) {
me->position.h += me->speed.h;
me->action=JumpFromHMov;
}
else
me->action=Jump;
me->JumpKey = Pushed;
}
}
}
// Down - Key Number 2
if (IsPressed(0x7D) || IsPressed(0x54)) ;
// - Clear Key
if (IsPressed(0x47)) ;
}